package com.example.carmessage2;

import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

public class Histroycord extends AppCompatActivity {
    ListView hislv;
    public static List<String> hislist;
    TextView hisdetails;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_histroycord);
        hislv = findViewById(R.id.hislv);
        hisdetails = findViewById(R.id.hisdetails);

        hislist = new ArrayList<>();

        hislist.add("2024/5/19");
        hislist.add("2024/3/23");
        hislist.add("2022/9/16");
        hislist.add("2024/3/27");
        hislist.add("2023/7/14");


        hislv.setAdapter(new ArrayAdapter(Histroycord.this, android.R.layout.simple_list_item_1, hislist));

                  hislv.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
                      @Override
                      public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
                                                 contextMenu.add("详细信息");


                      }
                  });
    }

    @Override
    public boolean onContextItemSelected(@NonNull MenuItem item) {

AdapterView.AdapterContextMenuInfo menuInfo= (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();


                             switch (item.getItemId()){

                                 case 0:
                                     Toast.makeText(Histroycord.this,"打开详细信息",Toast.LENGTH_SHORT).show();

                                       hisdetails.setVisibility(View.VISIBLE);

                                       if (hislist.get(menuInfo.position).equals("2024/5/19")){
                                           hisdetails.setText("2024/5/19的详细信息。。。。。。。。。。。。。。。。");
                                       }else if (hislist.get(menuInfo.position).equals("2024/3/23")){
                                           hisdetails.setText(hislist.get(menuInfo.position)+"的详细信息。。。。。。。。。。。。。。。。");
                                       }else if (hislist.get(menuInfo.position).equals("2022/9/16")) {
                                           hisdetails.setText(hislist.get(menuInfo.position) + "的详细信息。。。。。。。。。。。。。。。。");
                                       }   else if (hislist.get(menuInfo.position).equals("2024/3/27")) {
                                           hisdetails.setText(hislist.get(menuInfo.position) + "的详细信息。。。。。。。。。。。。。。。。");
                                       }
                                     break;


                             }

        return super.onContextItemSelected(item);
    }
}